easytrader 需要注意的地方
文档地址:https://easytrader.readthedocs.io/zh/master/ 项目地址:https://github.com/shidenggui/easytrader
1.安装:
pip install easytrader
pip install pywin32
升级
pip install easytrader -U
2.设置交易客户端类型
通用同花顺客户端
user = easytrader.use('universal_client')
3. 启动并连接客户端
同花顺客户端路径
user.connect(r'客户端xiadan.exe路径') # 类似 r'D:\Program Files\同花顺\xiadan.exe'
4. 设置客户端编辑文本形式:type_keys
user.enable_type_keys_for_editor()
例子
import easytrader
# 设置客户端信息(同花顺)
user = easytrader.use('universal_client')
# 连接客户端(同花顺:登录且保存密码且自动登录)
user.connect(r'D:\Program Files\同花顺\xiadan.exe') # 类似 r'C:\htzqzyb2\xiadan.exe'
# 设置客户端编辑文本形式:type_keys
user.enable_type_keys_for_editor()
# 调用常用函数
# 一类:查询类
# 查询持仓
balance = user.balance
print(balance)
# # 查询持仓(仓位)
# position = user.position
# print(position)
#
# 二类:交易
# 买入
# buy_no = user.buy('000002', price=26.78, amount=100)
# print(buy_no)
# 卖出
# sell_no = user.sell('300059', price='', amount=100)
# print(sell_no)
# 撤单:根据单号撤销,不稳定有效,待解决
# cancel = user.cancel_entrust('2795135376')
# print(cancel)
# # 撤单:全部撤销
# cancel = user.cancel_all_entrusts()
# print(cancel)
# # 查询当日成交
# today_trades = user.today_trades
# print(today_trades)
# # 查询当日委托
# today_entrusts = user.today_entrusts
# print(today_entrusts)